<html>
<head><meta charset="utf-8"><title>CHECK test fails even though code is present · t-compiler/wg-llvm · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/index.html">t-compiler/wg-llvm</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/CHECK.20test.20fails.20even.20though.20code.20is.20present.html">CHECK test fails even though code is present</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="199885616"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/CHECK%20test%20fails%20even%20though%20code%20is%20present/near/199885616" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nathan Corbyn <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/CHECK.20test.20fails.20even.20though.20code.20is.20present.html#199885616">(Jun 05 2020 at 14:38)</a>:</h4>
<p>I'm writing a test to check that some output ir contains</p>
<div class="codehilite"><pre><span></span><code><span class="k">define</span> <span class="k">void</span> <span class="vg">@a</span><span class="p">()</span>
</code></pre></div>


<p>When I run my local <code>rustc</code> build with <code>--emit=llvm-ir</code> and inspect the output the <code>define</code> is present, but when I run <code>./x.py test</code> the check test fails... Am I missing something obvious?</p>



<a name="199886204"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/CHECK%20test%20fails%20even%20though%20code%20is%20present/near/199886204" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/CHECK.20test.20fails.20even.20though.20code.20is.20present.html#199886204">(Jun 05 2020 at 14:43)</a>:</h4>
<p>The simplest explanation would be a simple typo e.g. in the CHECK line. Can you post the test and what <code>x.py test</code> prints when the test fails?</p>



<a name="199886452"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/CHECK%20test%20fails%20even%20though%20code%20is%20present/near/199886452" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nathan Corbyn <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/CHECK.20test.20fails.20even.20though.20code.20is.20present.html#199886452">(Jun 05 2020 at 14:45)</a>:</h4>
<div class="codehilite"><pre><span></span><code><span class="c1">// compile-flags: -C no-prepopulate-passes</span>

<span class="cp">#![crate_type = </span><span class="s">&quot;cdylib&quot;</span><span class="cp">]</span><span class="w"></span>

<span class="c1">// CHECK: define void @a()</span>
<span class="cp">#[no_mangle]</span><span class="w"></span>
<span class="cp">#[inline]</span><span class="w"></span>
<span class="k">pub</span><span class="w"> </span><span class="k">extern</span><span class="w"> </span><span class="s">&quot;C&quot;</span><span class="w"> </span><span class="k">fn</span> <span class="nf">a</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="c1">// side effect to keep `a` around</span>
<span class="w">    </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">core</span>::<span class="n">ptr</span>::<span class="n">read_volatile</span><span class="p">(</span><span class="o">&amp;</span><span class="mi">42</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p>with output</p>
<div class="codehilite"><pre><span></span><code>error: verification with &#39;FileCheck&#39; failed
status: exit code: 1
command: &quot;/home/nathan/git/rust/build/x86_64-unknown-linux-gnu/llvm/build/bin/FileCheck&quot; &quot;--input-file&quot; &quot;/home/nathan/git/rust/build/x86_64-unknown-linux-gnu/test/codegen/staticlib-external-no-mangle-fns/staticlib-external-no-mangle-fns.ll&quot; &quot;/home/nathan/git/rust/src/test/codegen/staticlib-external-no-mangle-fns.rs&quot;
stdout:
------------------------------------------

------------------------------------------
stderr:
------------------------------------------
/home/nathan/git/rust/src/test/codegen/staticlib-external-no-mangle-fns.rs:5:11: error: CHECK: expected string not found in input
// CHECK: define void @a()
          ^
/home/nathan/git/rust/build/x86_64-unknown-linux-gnu/test/codegen/staticlib-external-no-mangle-fns/staticlib-external-no-mangle-fns.ll:1:1: note: scanning from here
; ModuleID = &#39;staticlib_external_no_mangle_fns.3a1fbbbh-cgu.0&#39;
^
/home/nathan/git/rust/build/x86_64-unknown-linux-gnu/test/codegen/staticlib-external-no-mangle-fns/staticlib-external-no-mangle-fns.ll:2:5: note: possible intended match here
source_filename = &quot;staticlib_external_no_mangle_fns.3a1fbbbh-cgu.0&quot;
    ^

------------------------------------------
</code></pre></div>



<a name="199886739"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/CHECK%20test%20fails%20even%20though%20code%20is%20present/near/199886739" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nathan Corbyn <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/CHECK.20test.20fails.20even.20though.20code.20is.20present.html#199886739">(Jun 05 2020 at 14:46)</a>:</h4>
<p>But the output llvm contains</p>
<div class="codehilite"><pre><span></span><code><span class="c">; Function Attrs: inlinehint nounwind nonlazybind uwtable</span>
<span class="k">define</span> <span class="k">void</span> <span class="vg">@a</span><span class="p">()</span> <span class="k">unnamed_addr</span> <span class="vg">#1</span> <span class="p">{</span>
<span class="nl">start:</span>
  <span class="nv">%_4</span> <span class="p">=</span> <span class="k">load</span> <span class="k">i32</span><span class="p">*,</span> <span class="k">i32</span><span class="p">**</span> <span class="k">bitcast</span> <span class="p">(&lt;{</span> <span class="k">i8</span><span class="p">*,</span> <span class="p">[</span><span class="m">0</span> <span class="k">x</span> <span class="k">i8</span><span class="p">]</span> <span class="p">}&gt;*</span> <span class="vg">@anon.0cc175b9c0f1b6a831c399e269772661.0</span> <span class="k">to</span> <span class="k">i32</span><span class="p">**),</span> <span class="k">align</span> <span class="m">8</span><span class="p">,</span> <span class="nv">!nonnull</span> <span class="nv nv-Anonymous">!2</span>
<span class="c">; call core::ptr::read_volatile</span>
  <span class="nv">%_1</span> <span class="p">=</span> <span class="k">call</span> <span class="k">i32</span> <span class="vg">@_ZN4core3ptr13read_volatile17habdbcd7722f5eae5E</span><span class="p">(</span><span class="k">i32</span><span class="p">*</span> <span class="nv">%_4</span><span class="p">)</span>
  <span class="k">br</span> <span class="k">label</span> <span class="nv">%bb1</span>

<span class="nl">bb1:</span>                                              <span class="c">; preds = %start</span>
  <span class="k">ret</span> <span class="k">void</span>
<span class="p">}</span>
</code></pre></div>



<a name="199886982"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/CHECK%20test%20fails%20even%20though%20code%20is%20present/near/199886982" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/CHECK.20test.20fails.20even.20though.20code.20is.20present.html#199886982">(Jun 05 2020 at 14:48)</a>:</h4>
<p>To be clear, is the last snippet the file that x.py output refers to or generated manually by invoking rustc? Not sure if that would make a difference, but just to be sure.</p>



<a name="199887042"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/CHECK%20test%20fails%20even%20though%20code%20is%20present/near/199887042" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nathan Corbyn <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/CHECK.20test.20fails.20even.20though.20code.20is.20present.html#199887042">(Jun 05 2020 at 14:48)</a>:</h4>
<p>That's the  one from manually invoking rustc - should there be a difference between these?</p>



<a name="199887802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/CHECK%20test%20fails%20even%20though%20code%20is%20present/near/199887802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nathan Corbyn <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/CHECK.20test.20fails.20even.20though.20code.20is.20present.html#199887802">(Jun 05 2020 at 14:54)</a>:</h4>
<p>I have a feeling it might actually be an interaction between incremental compilation and the check tests - let me do a clean run (this might take a while)</p>



<a name="199892285"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/CHECK%20test%20fails%20even%20though%20code%20is%20present/near/199892285" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/CHECK.20test.20fails.20even.20though.20code.20is.20present.html#199892285">(Jun 05 2020 at 15:23)</a>:</h4>
<p>Try generating the IR with -O, maybe LLVM is adding some attributes to the definition.</p>



<a name="199895344"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/CHECK%20test%20fails%20even%20though%20code%20is%20present/near/199895344" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nathan Corbyn <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/CHECK.20test.20fails.20even.20though.20code.20is.20present.html#199895344">(Jun 05 2020 at 15:44)</a>:</h4>
<p>Thanks both of you! Turned out it was to do with MIR optimisations but I've fixed it now</p>



<a name="199896692"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/CHECK%20test%20fails%20even%20though%20code%20is%20present/near/199896692" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nathan Corbyn <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/CHECK.20test.20fails.20even.20though.20code.20is.20present.html#199896692">(Jun 05 2020 at 15:54)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> <span class="user-mention" data-user-id="124289">@Hanna Kruppe</span> would either of you mind taking a looking at <a href="https://github.com/rust-lang/rust/issues/73034">#73034</a>?</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>